package com.jf.docsify.common.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.jf.docsify.common.exception.DocsifyException;
import com.jfinal.plugin.activerecord.Db;

/**
 * Description:
 *
 * @author chenwr
 * @version 1.0
 *
 * <pre>
 * 修改记录:
 * 修改后版本           修改人       修改日期         修改内容
 * 2022/8/2.1       chenwr    2022/8/2           Create
 * </pre>
 * @date 2022/8/2
 */
public class DbTxUtil {

    /** logger */
    private static final Logger log = LoggerFactory.getLogger(DbTxUtil.class);

    private DbTxUtil() {
    }

    public static boolean tx(Run atom) {
        return Db.tx(() -> {
            try {
                atom.run();
                return true;
            } catch (Exception e) {
                DocsifyException.throwE(e);
            }
            return false;
        });
    }

    public interface Run {
        void run();
    }
}